import request from '@/utils/request';

// 添加商品到购物车
export const addToCart = (userId, productId, quantity) => {
  return request({
    url: '/cart/add',
    method: 'post',
    params: {
      userId,
      productId,
      quantity
    }
  });
};

// 获取用户购物车商品列表
export const getCartProducts = (userId) => {
  return request({
    url: '/cart/products',
    method: 'get',
    params: { userId }
  });
};

// 更新购物车商品数量
export const updateCartQuantity = (userId, cartId, quantity) => {
  return request({
    url: '/cart/update',
    method: 'post',
    data: {
      userId,
      cartId,
      quantity
    }
  });
};

// 删除购物车商品
export const deleteCartItem = (userId, cartId) => {
  return request({
    url: '/cart/delete',
    method: 'delete',
    params: {
      userId,
      cartId
    }
  });
};

// 清空购物车
export const clearCart = (userId) => {
  return request({
    url: '/cart/clear',
    method: 'delete',
    params: { userId }
  });
};

// 获取购物车基本信息
export const getCartInfo = (userId) => {
  return request({
    url: '/cart/all',
    method: 'get',
    params: { userId }
  });
}; 